home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DELPHI / LEDIT108.ZIP / LEMFC / LEMFC.H < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-10  |  22.3 KB  |  758 lines

  1. // =========================================================================
  2. //       LEdit wrapper for Microsoft MFC 2.5 & 3.0 (16-/32-bit Windows)
  3. //       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4. //       Version 1.08
  5. //       (c) 1996-1996 Andrey B. Yastrebov
  6. //       Nobody can modify this file without written permission of author
  7. //
  8. //       Limitations of current version:
  9. //       Summary length of all editing files: min(ca 60M,your memory)
  10. //       Maximum line length: 8K
  11. //
  12. //       This file containts full definitions and documentation on constants
  13. //       and functions needed to deal with LEdit MFC wrapper
  14. //       !!! Many things have different meaning than in stanard "CEdit" !!!
  15. //       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  16. //
  17. //       Windows      is a trademark of Microsoft corp.
  18. //
  19. //       If you have some questions please contact:  xor@hawk.usr.pu.ru
  20. // =========================================================================
  21. //
  22. //   Defines CLEdit classes:
  23. //
  24. //  CWnd ------------------------> CLEdit                                 
  25. //
  26. //  CView -----------------------> CLEditView
  27. //
  28. //  When working with these objects you may use ES_* constants for
  29. //  LEdit styles. See them in file LEDIT.H
  30. //
  31. //  File LEDIT.H also contains description of all structures
  32. //  and options very important while using LEdit.
  33. ////////////////////////////////////////////////////////
  34. #pragma pack(1)
  35. #pragma warning ( disable : 4010 )
  36. #include "ledit.h"
  37. #pragma pack()
  38.  
  39. #ifdef WIN32
  40. #define HUGE_PTR far
  41. #else
  42. #define HUGE_PTR huge
  43. #endif
  44. #if !defined(WM_CTLCOLOR)
  45. #define WM_CTLCOLOR WM_CTLCOLOREDIT
  46. #endif
  47. #if !defined(FP_OFF)
  48. #define FP_OFF(ptr) LOWORD((long)ptr)
  49. #endif
  50. #if !defined(FP_SEG)
  51. #define FP_SEG(ptr) HIWORD((long)ptr)
  52. #endif
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CLEdit window
  55.  
  56. class CLEdit : public CWnd
  57. {     
  58. protected:
  59.     DECLARE_DYNCREATE(CLEdit)
  60.  
  61. // Construction
  62. public:
  63.     CLEdit();
  64.  
  65. // Operations
  66. public:
  67.      //
  68.      // Sets font
  69.      //
  70.      void SetFont(HFONT font)
  71.         {SendMessage(WM_SETFONT,(WPARAM) font);}
  72.      void SetFont(LOGFONT& font)
  73.         {SendMessage(EM_SETLOGFONT,0,(LPARAM) &font);}
  74.      //
  75.      // Sets syntax. May be used at any time. See LEDIT.H for
  76.      // detailed information. Or alternative form as in VBX
  77.      // or Delphi VCL wrappers may be used with string supplied
  78.      // to function.
  79.      //
  80.      void SetSyntax(SYNTAX far* syntax, int syntaxLength, int flags = 0)
  81.         {SendMessage(EM_SETSYNTAX,syntaxLength + (flags << 8),
  82.            (LPARAM) syntax);}
  83.      void SetSyntax(char far* syntax, int flags = 0);
  84.  
  85.      //******* The following functions constitute syntax parser ************
  86.  
  87.      //
  88.      // Starts parsing process and move pointer position (PP) to the
  89.      // beginning of the text
  90.      //
  91.      void SetScan()
  92.         {SendMessage(EM_SETSCAN);}
  93.  
  94.      //
  95.      // Retrieves current word from PP and move PP to the end of it.
  96.      // Return status of the operation
  97.      //
  98.      int GetWord(WORDDESC& wordDesc, BOOL skipLines = TRUE)
  99.         {return LOWORD(SendMessage(EM_GETWORD,skipLines,(LPARAM) &wordDesc));}
  100.  
  101.      //
  102.      // Moves PP to the begin of the next line
  103.      //
  104.      int NextLine()
  105.         {return LOWORD(SendMessage(EM_NEXTLINE));}
  106.  
  107.      //
  108.      // Gets the rest of line from PP to the next of line. Doesn't
  109.      // move PP.
  110.      // In the second form allocates memory using new and pass
  111.      // returns its address
  112.      //
  113.      int GetRestOfLine(char far* buf)
  114.         {return LOWORD(SendMessage(EM_GETRESTOFLINE,0,(LPARAM) buf));}
  115.  
  116.      //
  117.      // Retrieves position of last word read by GetWord() or start of
  118.      // new line set by NewLine()
  119.      //
  120.      int GetScan(LEDITPOSITION& Pos)
  121.         {return LOWORD(SendMessage(EM_GETSCAN,0,(LPARAM) &Pos));}
  122.  
  123.      //******* End of syntax parser *****************************************
  124.  
  125.      //
  126.      // Retrieves current word from the caret position.
  127.      // Return status of the operation
  128.      //
  129.      int GetCurrentWord(WORDDESC& wordDesc)
  130.         {return LOWORD(SendMessage(EM_GETCURRENTWORD,0,(LPARAM) &wordDesc));}
  131.  
  132.      //
  133.      // Returns number of lines in LEdit
  134.      //
  135.      long GetNumLines()
  136.         {return SendMessage(EM_EX_GETLINECOUNT);}
  137.      long GetLineCount()
  138.         {return SendMessage(EM_EX_GETLINECOUNT);}
  139.  
  140.      //
  141.      // Returns the length of specified line
  142.      //
  143.      long GetLineLength(long lineNumber)
  144.         {return SendMessage(EM_EX_LINELENGTH,0,lineNumber);}
  145.  
  146.      //
  147.      // Returns specified line. Buffer str must be large enough.
  148.      // Returns the length of the line.
  149.      //
  150.      long GetLine(char far* str, long lineNumber)
  151.        { *(long far*) str = lineNumber;
  152.          return SendMessage(EM_EX_GETLINE,0,(LPARAM) str);}
  153.  
  154.      //
  155.      // Returns Selected position
  156.      //
  157.      void GetSelection(LEDITPOSITION& Pos)
  158.         {SendMessage(EM_EX_GETSEL,0,(LPARAM) &Pos);}
  159.  
  160.      //
  161.      // Sets selected position
  162.      //
  163.      void SetSelection(const LEDITPOSITION& Pos)
  164.         {SendMessage(EM_EX_SETSEL,0,(LPARAM) &Pos);}
  165.      void SetSelection(long StartLine,short int StartPosition, long EndLine,
  166.         short int EndPosition);
  167.  
  168.      //
  169.      // Returns text length
  170.      //
  171.      long GetTextLength()
  172.         {return SendMessage(EM_GETTEXTLENGTH,EMP_ALLTEXT);}
  173.  
  174.      //
  175.      // Returns text
  176.      //
  177.      BOOL GetText(char HUGE_PTR* str)
  178.         {return ! SendMessage(EM_GETTEXT,EMP_ALLTEXT,(LPARAM) str);}
  179.      BOOL GetText(char HUGE_PTR* str, long maxChars)
  180.         {return ( maxChars > GetTextLength()) ? GetText(str) : FALSE; }
  181.      HANDLE GetText();
  182.  
  183.      //
  184.      // Replaces text
  185.      //
  186.      void SetText(const char HUGE_PTR* str)
  187.         {SendMessage(EM_SETTEXT,EMP_ALLTEXT,(LPARAM) str);}
  188.      void SetText(HANDLE hGlobal);
  189.  
  190.      //
  191.      // Returns Selected text length
  192.      //
  193.      long GetSelLength()
  194.         {return SendMessage(EM_GETSELTEXTLENGTH);}
  195.  
  196.      //
  197.      // Returns Selected text
  198.      //
  199.      BOOL GetSelText(char HUGE_PTR* str)
  200.         {return ! SendMessage(EM_GETSELTEXT,0,(LPARAM) str);}
  201.      BOOL GetSelText(char HUGE_PTR* str, long maxChars)
  202.         {return ( maxChars > GetSelLength()) ? GetSelText(str) : FALSE;}
  203.      HANDLE GetSelText();
  204.  
  205.      //
  206.      // Replaces Selected text
  207.      //
  208.      void SetSelText(const char HUGE_PTR* str)
  209.         {SendMessage(EM_EX_REPLACESEL,0,(LPARAM) str);}
  210.      void SetSelText(HANDLE hGlobal);
  211.  
  212.      //
  213.      // Verifies if the text was modified since last ClearModify()
  214.      //
  215.      BOOL IsModified(int flagNumber = 2)
  216.         {return LOWORD(SendMessage(EM_EX_GETMODIFY,flagNumber));}
  217.  
  218.      //
  219.      // Sets or Clears modify flag
  220.      //
  221.      void SetModify(int fSetOrClear, int flagNumber = 2)
  222.         {SendMessage(EM_EX_SETMODIFY,fSetOrClear,flagNumber);}
  223.  
  224.      //
  225.      // Clears modify flag
  226.      //
  227.      void ClearModify(int flagNumber = 2)
  228.         {SetModify(EMP_CLEAR,flagNumber);}
  229.  
  230.      //
  231.      // Deletes all text
  232.      //
  233.      void DeleteText()
  234.         {SendMessage(EM_CLEAR,EMP_ALLTEXT);}
  235.  
  236.      //
  237.      // The same as SetSelText - exists only for compatibility.
  238.      //
  239.      void Insert(const char far* str)
  240.         {SetSelText(str);}
  241.  
  242.      //
  243.      // Set number of cahrs equivalent to one tab (1 - 40)
  244.      //
  245.      void SetTabStops(int numTabs)
  246.         {SendMessage(EM_EX_SETTABSTOPS,numTabs);}
  247.  
  248.      //
  249.      // Returns handle of pop-up menu
  250.      //
  251.      HMENU GetPopUpMenu()
  252.         {SendMessage(EM_SETRUNTIMEFLAGS,EMP_16_AS32);
  253.          return (HMENU) SendMessage(EM_EX_GETHANDLE,EMP_32_MENU);}
  254.  
  255.      //
  256.      // Returns handle of main menu if ES_HASMENU
  257.      //
  258.      HMENU GetMenu()                      
  259.         {SendMessage(EM_SETRUNTIMEFLAGS,EMP_16_AS32);
  260.          return (HMENU) SendMessage(EM_EX_GETHANDLE,EMP_32_POPUP);}
  261.  
  262.      //
  263.      // Returns number of first visible line
  264.      //
  265.      long GetFirstVisibleLine()
  266.         {return SendMessage(EM_GETFIRSTVISIBLELINE);}
  267.  
  268.      //
  269.      // Returns number of leftmost visible position in units that
  270.      // may be retrieved with GetUnitsHorizontal()
  271.      //
  272.      int GetFirstVisiblePos()
  273.         {return LOWORD(SendMessage(EM_GETHORZPOSITION));}
  274.  
  275.      //
  276.      // Gets line height in pixels
  277.      //
  278.      int GetUnitsVertical()
  279.         {return HIWORD(SendMessage(EM_GETUNITS));}
  280.  
  281.      //
  282.      // Gets horizontl scrolling unit in pixels
  283.      //
  284.      int GetUnitsHorizontal()
  285.         {return LOWORD(SendMessage(EM_GETUNITS));}
  286.  
  287.      //
  288.      // Sets/Clears read-only flag
  289.      //
  290.      void SetReadOnly(BOOL readOnly = TRUE)
  291.        {SendMessage(EM_EX_SETREADONLY,readOnly ? EMP_SET : EMP_CLEAR);}
  292.  
  293.      //
  294.      // Sets/Clears ES_HIGHLIGHT flag
  295.      //
  296.      void SetHighlight(BOOL highlight = TRUE)
  297.        {SendMessage(EM_SETHIGHLIGHT, highlight ? EMP_SET : EMP_CLEAR);}
  298.        
  299.      //
  300.      // Sets/Clears ES_TRANSPARENT flag
  301.      //
  302.      void SetTransparent(BOOL transparent = TRUE)
  303.        {SendMessage(EM_SETTRANSPARENT, transparent ? EMP_SET : EMP_CLEAR);}
  304.  
  305.      //
  306.      // Sets/Clears WS_HSCROLL and WS_VSCROLL flag
  307.      //
  308.      void SetScrollBars(BOOL horzScrollBar, BOOL vertScrollBar);
  309.      void SetHorzScrollBar(BOOL horzSctollBar);
  310.      void SetVertScrollBar(BOOL vertScrollBar);
  311.  
  312.      //
  313.      // Sets external spacing in Pixels. Works only when control
  314.      // window is created and allow setting spacing in range 0 - 15
  315.      //
  316.      void SetExtraSpacing(short horzSpacing, short vertSpacing);
  317.      void SetExtraHorzSpacing(short horzSpacing);
  318.      void SetExtraVertSpacing(short vertSpacing);
  319.  
  320.      //
  321.      // Resets file information and sets ES_HASFILE according to hasFile
  322.      // This method doesn't change menu.
  323.      //
  324.      void ResetFileState(BOOL hasFile = TRUE)
  325.        {SendMessage(EM_RESETFILESTATE,
  326.          (hasFile) ? EMP_EMPTYFILE : EMP_NOFILE);}
  327.  
  328.      //
  329.      // Sets insert mode
  330.      //
  331. #define IM_INSERT    FALSE
  332. #define IM_OVERWRITE TRUE
  333.      void SetInsertMode(BOOL insertMode = IM_INSERT)
  334.         {SendMessage(EM_SETINSERTMODE,insertMode);}
  335.        
  336.      //
  337.      // Sets AutoIndent state
  338.      //
  339.      void SetAutoIndent(BOOL autoIndent = TRUE)
  340.         {autoIndent ? SendMessage(EM_SETRUNTIMEFLAGS,EMP_AUTOINDENT)
  341.          : SendMessage(EM_SETRUNTIMEFLAGS,0,EMP_AUTOINDENT);}
  342.  
  343.      //
  344.      // Sets DefaultSelection State
  345.      //
  346.      void SetDefaultSelection(BOOL defaultSelection = TRUE)
  347.            {defaultSelection ? SendMessage(EM_SETRUNTIMEFLAGS,EMP_DEFAULTSELECTION)
  348.          : SendMessage(EM_SETRUNTIMEFLAGS,0,EMP_DEFAULTSELECTION);}
  349.  
  350.  
  351.      //
  352.      // Sets MultilineItems state
  353.      //
  354.      void SetMultilineItems(BOOL multilineItems = TRUE)
  355.         {multilineItems ? SendMessage(EM_SETRUNTIMEFLAGS,EMP_MULTILINEITEMS)
  356.          : SendMessage(EM_SETRUNTIMEFLAGS,0,EMP_MULTILINEITEMS);}
  357.  
  358.      //
  359.      // Sets CurrentWordAsText state
  360.      //
  361.      void SetCurrentWordAsText(BOOL currentWordAsText = TRUE)
  362.         {currentWordAsText ? SendMessage(EM_SETRUNTIMEFLAGS,EMP_CURRENTWORDASTEXT)
  363.          : SendMessage(EM_SETRUNTIMEFLAGS,0,EMP_CURRENTWORDASTEXT);}
  364.  
  365.      //
  366.      // Sets UnixStyleSave state
  367.      //
  368.      void SetUnixStyleSave(BOOL unixStyleSave = TRUE)
  369.         {unixStyleSave ? SendMessage(EM_SETRUNTIMEFLAGS,EMP_UNIXSTYLESAVE)
  370.          : SendMessage(EM_SETRUNTIMEFLAGS,0,EMP_UNIXSTYLESAVE);}
  371.  
  372.      //
  373.      // Sets MacStyleSave state
  374.      //
  375.      void SetMacStyleSave(BOOL macStyleSave = TRUE)
  376.            {macStyleSave ? SendMessage(EM_SETRUNTIMEFLAGS,EMP_MACSTYLESAVE)
  377.          : SendMessage(EM_SETRUNTIMEFLAGS,0,EMP_MACSTYLESAVE);}
  378.      
  379.      //
  380.      // Sets StartInComments flag that forces LEdit to think that
  381.      // there's the line with open comment sign before the text
  382.      //
  383.      void SetStartInComments(BOOL startInComments = TRUE)
  384.            {startInComments ? SendMessage(EM_SETRUNTIMEFLAGS,EMP_STARTINCOMMENTS)
  385.          : SendMessage(EM_SETRUNTIMEFLAGS,0,EMP_STARTINCOMMENTS);}
  386.          
  387.     //
  388.     // Sets search flags. See EM_SETFINDFLAGS in LEDIT.H for details
  389.     //
  390.     void SetSearchFlags(long flags = 0)
  391.       {SendMessage(EM_SETFINDFLAGS,0,flags);}
  392.  
  393.     //
  394.     // Gets search flags.
  395.     //
  396.     long GetSearchFlags()
  397.       {return SendMessage(EM_GETFINDFLAGS);}
  398.  
  399.     //
  400.     // Sets the string to be found by Find and FindNext methods
  401.     //
  402.     void SetSearchFindText(char far* text)
  403.       {SendMessage(EM_SETFINDTEXT,EMP_FIND,(LPARAM) text);}
  404.  
  405.     //
  406.     // Gets the string to be found by Find and FindNext methods
  407.     // buffer must be at least 128 bytes
  408.     //
  409.     void GetSearchFindText(char far* buffer)
  410.       {SendMessage(EM_GETFINDTEXT,EMP_FIND,(LPARAM) buffer);}
  411.  
  412.     //
  413.     // Sets the string to replace matches found in Replace and
  414.     // ReplaceAll methods
  415.     //
  416.     void SetSearchReplaceText(char far* text)
  417.       {SendMessage(EM_SETFINDTEXT,EMP_REPLACE,(LPARAM) text);}
  418.  
  419.     //
  420.     // Sets the string to replace matches found in Replace and
  421.     // ReplaceAll methods
  422.     // buffer must be at least 128 bytes
  423.     //
  424.     void GetSearchReplaceText(char far* buffer)
  425.       {SendMessage(EM_GETFINDTEXT,EMP_REPLACE,(LPARAM) buffer);}
  426.  
  427.     //
  428.     // Finds the text specified. Returns 1 if match was found and
  429.     // highlighted. -1 indicates error.
  430.     //
  431.     short Find()
  432.       {return LOWORD(SendMessage(EM_FIND,EMP_FIND));}
  433.     short Find(char far* what)
  434.       {SetSearchFindText(what); return Find();}
  435.     short Find(char far* what, long flags)
  436.       {SetSearchFlags(flags); return Find(what);}
  437.  
  438.     //
  439.     // Verifies if currently selected text matches search criteria
  440.     // and then replaces it. Returns 1 if match was found and
  441.     // replaced. -1 indicates error.
  442.     //
  443.     short Replace()
  444.       {return LOWORD(SendMessage(EM_FIND,EMP_REPLACE));}
  445.     short Replace(char far* byWhat)
  446.       {SetSearchReplaceText(byWhat); return Replace();}
  447.     short Replace(char far* what, char far* byWhat)
  448.       {SetSearchFindText(what); return Replace(byWhat);}
  449.     short Replace(char far* byWhat, long flags)
  450.       {SetSearchFlags(flags); return Replace(byWhat);}
  451.     short Replace(char far* what, char far* byWhat, long flags)
  452.       {SetSearchFlags(flags); return Replace(what, byWhat);}
  453.  
  454.     //
  455.     // Replaces all occurrences of one string by another. Returns
  456.     // number of occurrences replaced. -1 indicates error.
  457.     //
  458.     long ReplaceAll()
  459.       {return SendMessage(EM_FIND,EMP_REPLACEALL);}
  460.     long ReplaceAll(char far* what, char far* byWhat)
  461.       {SetSearchFindText(what); SetSearchReplaceText(byWhat);
  462.         return ReplaceAll();}
  463.     long ReplaceAll(char far* what, char far* byWhat, long flags)
  464.       {SetSearchFlags(flags); return ReplaceAll(what, byWhat);}
  465.     long ReplaceAll(long flags)
  466.       {SetSearchFlags(flags); return ReplaceAll();}
  467.  
  468.     //
  469.     // Sets bookmark with specified number at specified line
  470.     // Operates only when LEdit window exists. number may be
  471.     // between 0 and 15.
  472.     //
  473.     int SetBookmark(int number, int line)
  474.       {return LOWORD(SendMessage(EM_SETBMLINE,number,line));}
  475.     int SetBookmark(int line)
  476.       {return SetBookmark(0,line);}
  477.  
  478.     //
  479.     // Retrieves number of line at which bookmark with specified
  480.     // number was set. This number of line may change as user
  481.     // edits text and inserts/removes lines
  482.     //
  483.     long GetBookmarkLine(int number = 0)
  484.       {return SendMessage(EM_GETBMLINE,number);}
  485.  
  486.     //
  487.     // Set Foreground color to be used to highlight bookmark
  488.     //
  489.     void SetBookmarkForeColor(int number, COLORREF color)
  490.       {SendMessage(EM_SETBMATTRIBUTES,number +
  491.         ((EMP_SETTEXTCOLOR | EMP_STARTTEXTCOLOR) << 8),color);}
  492.     void SetBookmarkForeColor(COLORREF color)
  493.        {SetBookmarkForeColor(0,color);}
  494.  
  495.      //
  496.      // Stops Foreground highlight of specified bookmark
  497.      //
  498.      void RemoveBookmarkForeColor(int number = 0)
  499.         {SendMessage(EM_SETBMATTRIBUTES,number+(EMP_STOPTEXTCOLOR << 8));}
  500.  
  501.      //
  502.      // Set Background color to be used to highlight bookmark
  503.      //
  504.      void SetBookmarkBackColor(int number, COLORREF color)
  505.         {SendMessage(EM_SETBMATTRIBUTES,number +
  506.           ((EMP_SETBKCOLOR | EMP_STARTBKCOLOR) << 8),color);}
  507.      void SetBookmarkBackColor(COLORREF color)
  508.         {SetBookmarkBackColor(0,color);}
  509.  
  510.      //
  511.      // Stops Foreground highlight of specified bookmark
  512.      //
  513.      void RemoveBookmarkBackColor(int number = 0)
  514.        {SendMessage(EM_SETBMATTRIBUTES,number+(EMP_STOPBKCOLOR << 8));}
  515.  
  516.      //
  517.      // Gets maximum possible depth of Undo. Works only
  518.      // when window exists
  519.      //
  520.      int GetUndoMaxBuffer()
  521.         {return LOWORD(SendMessage(EM_GETMAXUNDOBUFFER));}
  522.  
  523.      //
  524.      // Sets the depth of undo. -1 means maximum possible depth
  525.      //
  526.      void SetUndoDepth(int undoDepth = -1);
  527.  
  528.      //
  529.      // Fill in the control with text from file
  530.      //
  531.      BOOL LoadFromFile(const char far* fileName)
  532.         {return !LOWORD(SendMessage(EM_SETTEXTFROMFILE,0,(LPARAM) fileName));}
  533.     
  534.      //
  535.      // Stores control containt into the file
  536.      //
  537.      BOOL StoreToFile(const char far* fileName)
  538.         {return !LOWORD(SendMessage(EM_GETTEXTTOFILE,0,(LPARAM) fileName));}
  539.       
  540.      //
  541.      // Takes one of EC_* constants and determines whether the command
  542.      // may be executed. 
  543.      // 
  544.      BOOL CanExecute(WORD commandId)
  545.        {return LOWORD(SendMessage(EM_CANEXECUTECOMMAND,commandId));}
  546.  
  547. #define MENU_COMMAND(MC_fn,MC_cmd) \
  548.       void MC_fn() {SendMessage(WM_COMMAND,MC_cmd);}
  549.     
  550.      //
  551.      // Edit operations
  552.      //
  553.      BOOL CanUndo()
  554.         {return LOWORD(SendMessage(EM_EX_CANUNDO,EMP_UNDO));}
  555.      BOOL CanRedo()
  556.         {return LOWORD(SendMessage(EM_EX_CANUNDO,EMP_UNDO));}
  557.      BOOL IsSelection();
  558.  
  559.      void Undo()
  560.         {SendMessage(EM_EX_UNDO,EMP_UNDO);}
  561.      void Redo()
  562.         {SendMessage(EM_EX_UNDO,EMP_REDO);}
  563.      void Cut()
  564.         {SendMessage(WM_CUT);}
  565.      void Copy()
  566.         {SendMessage(WM_COPY);}
  567.      void Paste()
  568.         {SendMessage(WM_PASTE);}
  569.      MENU_COMMAND(Duplicate,EC_EDITDUPLICATE)
  570.      void DeleteSelection()
  571.         {SendMessage(EM_CLEAR,EMP_SELECTION);}
  572.      MENU_COMMAND(SelectAll,EC_EDITSELECTALL)
  573.  
  574.      //
  575.      // Search operations
  576.      //
  577.      BOOL CanFindNext()
  578.         {return LOWORD(SendMessage(EM_CANFINDNEXT));}
  579.  
  580.      MENU_COMMAND(ShowFindDialog,EC_SEARCHFIND)
  581.      MENU_COMMAND(FindNext,EC_SEARCHNEXT)
  582.      MENU_COMMAND(ShowReplaceDialog,EC_SEARCHREPLACE)
  583.      MENU_COMMAND(FindBrace,EC_SEARCHBRACE)
  584.      MENU_COMMAND(ShowGotoLineDialog,EC_SEARCHLINE)
  585.      MENU_COMMAND(FindBookmark,EC_SEARCHBOOKMARK)
  586.      MENU_COMMAND(SetBookmark,EC_SEARCHSETBOOKMARK)
  587.  
  588.      //
  589.      // Tools operations
  590.      //
  591.      MENU_COMMAND(ShowFontDialog,EC_TOOLSCHANGEFONT)
  592.      void EmptyUndoBuffer()
  593.         {SendMessage(EM_EX_EMPTYUNDOBUFFER);}
  594.      void Clear()
  595.         {SendMessage(WM_CLEAR,EMP_ALLTEXT);}
  596.  
  597.      //
  598.      // Return TRUE if this is LEditWindow
  599.      //
  600.      BOOL IsLEdit()
  601.         {return (SendMessage(EM_ISLEDITWINDOW,0,543210L) == 543211L);}
  602.  
  603.      // Returns file name. Buffer fileName must be large enough.
  604.      // Returns the length of the line.
  605.      // In the second form allocates memory using new and
  606.      // returns its address
  607.      //
  608.      long GetFileName(char far* fileName)
  609.         {return SendMessage(EM_GETFILENAME,0,(LPARAM) fileName);}
  610.  
  611.      //
  612.      // Sets File Mask/Filter (see EM_SETFILEMASK)
  613.      //
  614.      void SetFileMask(char far* fileMask)
  615.        {SendMessage(EM_SETFILEFILTER,0, (LPARAM) fileMask);}
  616.  
  617.      //
  618.      // File operations
  619.      //
  620.      MENU_COMMAND(NewFile,EC_FILENEW)
  621.      MENU_COMMAND(OpenFile,EC_FILEOPEN)
  622.      MENU_COMMAND(ReloadFile,EC_FILEREOPEN)
  623.      MENU_COMMAND(SaveFile,EC_FILESAVE)
  624.      MENU_COMMAND(SaveFileAs,EC_FILESAVEAS)
  625.  
  626.     // Overrides
  627.     // ClassWizard generated virtual function overrides
  628.     //{{AFX_VIRTUAL(CLEdit)
  629.     //}}AFX_VIRTUAL
  630.  
  631. // Implementation
  632. public:
  633.     virtual ~CLEdit();
  634.         virtual BOOL Create(DWORD dwStyle, const RECT& rect, 
  635.            CWnd* pParentWnd, UINT nID);
  636.  
  637. protected:
  638.         WNDPROC* GetSuperWndProcAddr();
  639.  
  640.     //{{AFX_MSG(CLEdit)
  641.         // NOTE - the ClassWizard will add and remove member functions here.
  642.     //}}AFX_MSG
  643.     DECLARE_MESSAGE_MAP()
  644. };
  645.  
  646. /////////////////////////////////////////////////////////////////////////////
  647.  
  648. /////////////////////////////////////////////////////////////////////////////
  649. // CLEditView view
  650.  
  651. class CLEditView : public CView
  652. {
  653. protected:
  654.     CLEditView();           // protected constructor used by dynamic creation
  655.     DECLARE_DYNCREATE(CLEditView)
  656.     static const DWORD dwStyleDefault;
  657.     
  658. // Attributes
  659. public:                             
  660.     // Color sheme
  661.     COLORREF m_clrBackColor;
  662.     COLORREF m_clrForeColor;
  663.     COLORREF m_clrBackColorSelected;
  664.     COLORREF m_clrForeColorSelected;
  665.     
  666.     // Mode of behind text drawing
  667.     BOOL m_bUseMemoryDC;
  668.  
  669.     // CLEdit control access
  670.     CLEdit& GetLEditCtrl() const;
  671.  
  672. // Public access
  673. public:
  674.  
  675. // Overrideables
  676. protected:    
  677.  
  678.    // Command handlers
  679.    virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  680.    virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
  681.         AFX_CMDHANDLERINFO* pHandlerInfo);
  682.  
  683.    // EVENTS  
  684.    
  685.    // Handles drawing behind the text. Needs ES_TRANSPARENT
  686.    virtual void OnDrawBehind(CDC* pDC);                    
  687.    
  688.    // Handles highlight of every single word. Neesa ES_HIGHLIGHT
  689.    virtual void OnControlHighlight(WORDDESC& WD, CDC* pDC);     
  690.    
  691.    // Handles looking for brace.
  692.    virtual short OnFindBrace(WORDDESC& WD);
  693.    
  694.    // Handles double-clicking over every word.
  695.    virtual short OnWordClick(WORDDESC& WD);
  696.                
  697.    // Any changes including caret movement               
  698.    virtual void OnChange();
  699.    
  700.    // Scrolling
  701.    virtual void OnHorzScroll();
  702.    virtual void OnVertScroll(); 
  703.    
  704.    // Loading new file
  705.    virtual void OnNewFile();
  706.    
  707.    // Loading new font
  708.    virtual void OnNewFont();
  709.    
  710.    // Changing insertion mode
  711.    virtual void OnChangeMode();
  712.    
  713.    // Closing file. Default implementation checks whether it's modified
  714.    virtual short OnGoingToClose();
  715.    
  716.    // Should fire dialog about saving file
  717.    virtual short OnAskIfStoreFile();
  718.    
  719.    // Different kinds of Errors
  720.    virtual short OnFileError();
  721.    virtual short OnClipboardError();
  722.    virtual short OnMaxText();
  723.    virtual short OnSpaceError();
  724.  
  725. // Implementation
  726. public:
  727.     virtual ~CLEditView();
  728.  
  729.     virtual void OnDraw(CDC* pDC);
  730.     virtual void Serialize(CArchive& ar);
  731.     virtual void SerializeRaw(CArchive& ar);
  732.     virtual void DeleteContents();
  733.     void ReadFromArchive(CArchive& ar, DWORD dwLen);
  734.     void WriteToArchive(CArchive& ar);
  735.  
  736. protected:
  737.     // construction
  738.     WNDPROC* GetSuperWndProcAddr();
  739.     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
  740.  
  741.     //{{AFX_MSG(CLEditView)
  742.         // NOTE - the ClassWizard will add and remove member functions here.
  743.     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  744.     afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
  745.     afx_msg LRESULT OnEmCtlColor(WPARAM wp, LPARAM lp);
  746.     afx_msg LRESULT OnEmCtlColorEx(WPARAM wp, LPARAM lp);
  747.     afx_msg LRESULT OnEmDraw(WPARAM wp, LPARAM lp);
  748.     afx_msg LRESULT OnEmFindBrace(WPARAM wp, LPARAM lp);
  749.     afx_msg LRESULT OnEmWordClick(WPARAM wp, LPARAM lp);
  750.     afx_msg void OnPaint();
  751.     //}}AFX_MSG
  752.     DECLARE_MESSAGE_MAP()
  753. };
  754.     
  755. /////////////////////////////////////////////////////////////////////////////
  756. inline CLEdit& CLEditView::GetLEditCtrl() const
  757.         { return *(CLEdit*)this; }
  758.